#ifndef __H_MY_DEF_H__
#define __H_MY_DEF_H__

#include <google/protobuf/repeated_field.h>
#include <string>
#include <sstream>

#include "cmd.h"
#include "Packet.h"
#include "globalDefine.h"



#include "cmd.h"
#include "Packet.h"
#include "globalDefine.h"


// 过期时间定义
#define TIME_SECOND_SEC             1
#define TIME_MINUTE_SEC             60
#define TIME_HOUR_SEC               3600
#define TIME_DAY_SEC                86400
#define TIME_UPDATE_ROUTE_SEC       TIME_MINUTE_SEC * 3
#define TIME_MONTH_SEC              TIME_DAY_SEC * 30
#define TS_USER_ACCOUNT_EXPIRE      TIME_DAY_SEC * 7
#define TH_USER_BASIC_EXPIRE        TIME_DAY_SEC * 7
#define TH_USER_GAME_EXPIRE         TIME_DAY_SEC * 7
#define TH_USER_ITEM_EXPIRE         TIME_DAY_SEC * 7
#define TH_USER_DAY_EXPIRE          TIME_DAY_SEC
#define TIME_ORDER_EXPIRE           TIME_DAY_SEC
#define TZ_RANK_EXPIRE              TIME_DAY_SEC * 30
#define TH_ROOM_ONLINE_EXPIRE       TIME_DAY_SEC
#define TS_MAIL_EXPIRE              TIME_DAY_SEC * 90
#define TIME_BIG_MONTH_SEC          TIME_DAY_SEC * 31
#define TIME_WEEK_SEC               TIME_DAY_SEC * 7
#define TS_USER_TOKEN_EXPIRE        TIME_DAY_SEC * 2
#define LOGIN_CACHE_EXPIRE          2

enum TimerID
{
	TIMER_LOGIN_CACHE_CHECK = 1,
	TIMER_MINITE = 2,
};

const std::string USER_KEY("user:");       				// 游戏账号数据
const std::string USER_ID_KEY("user:id:");       			// 游戏账号数据

const int TH_TABLE = 100;															    // 哈希表
const std::string TS_LOGIN_TOKEN("H7iJ4kL5m6N1oP2qR3sT4uV5wX6Y7e8F9g0");       			// token密钥
const uint32 TS_LOGIN_TOKEN_EXPIRE_TIME(28800);   										// tokenRedisKey:userid:expire token过期时间
const int AVATAR_NUM = 20;		// 20个头像




inline std::string ToString(const ::google::protobuf::RepeatedPtrField< ::std::string>& items, char sep = ',')
{
	std::stringstream ss;
	for (auto it = items.begin(); it != items.end(); it++)
	{
		if (it != items.begin())
		{
			ss << sep;
		}
		ss << *it;
	}
	return ss.str();
}

inline void FromString(::google::protobuf::RepeatedPtrField< ::std::string>& items, const std::string& str, char sep = ',')
{
	char* s = const_cast<char*>(str.data());
	char* e = s + str.size();
	char* p_s = s;
	char* p_e = s;
	while (p_e < e)
	{
		if (*p_e != sep)
		{
			p_e++;
			if (p_e != e) 
			{
				continue;
			}
		}
		items.Add(std::move(std::string(p_s, p_e)));
		if (p_e == e)
		{
			break;
		}
		p_e++;
		p_s = p_e;
	}
}

struct TokenInfo
{
	TokenInfo(){ reset(); }
	void reset() {
		uid = 0; balance = 0; game = 0; gameinfo = ""; expi = 0; sign = ""; 
	}
	std::string uuid;
	std::uint32_t uid;
	std::string token;
	std::int64_t balance;
	std::uint32_t game;
	std::string gameinfo;
	std::uint64_t expi;
	std::string sign;
};


struct stCacheLoginInfo
{
	std::uint32_t agentSrvId;
	std::uint32_t uid;
	std::uint32_t tempUin;
	std::string agency;
	std::uint32_t agencyId;
	std::string username;
	std::string token;
	std::int64_t balance;
	std::uint32_t game;
	std::string hallUrl;
	std::string platform;
	std::string ext;
	std::string currency;
	std::uint64_t procTime;
	std::string trans;
	std::int64_t currency_unit_multi;
	std::string currency_label;

	stCacheLoginInfo() :agentSrvId(0), uid(0), tempUin(0), agencyId(0), balance(0), game(0), procTime(0),currency_unit_multi(0)
	{

	}
	stCacheLoginInfo(const stCacheLoginInfo& other)
	{
		agentSrvId = other.agentSrvId;
		uid = other.uid;
		tempUin = other.tempUin;
		agency = other.agency;
		agencyId = other.agencyId;
		username = other.username;
		token = other.token;
		balance = other.balance;
		game = other.game;
		hallUrl = other.hallUrl;
		platform = other.platform;
		ext = other.ext;
		currency = other.currency;
		procTime = other.procTime;
		trans = other.trans;
		currency_unit_multi = other.currency_unit_multi;
		currency_label = other.currency_label;
	}

	stCacheLoginInfo(stCacheLoginInfo&& other) : agency(std::move(other.agency)), username(std::move(other.username)), token(std::move(other.token)), hallUrl(std::move(other.hallUrl)), platform(std::move(other.platform)), ext(std::move(other.ext)), currency(std::move(other.currency)), trans(std::move(other.trans)), currency_label(std::move(other.currency_label))
	{
		agentSrvId = other.agentSrvId;
		uid = other.uid;
		tempUin = other.tempUin;
		agencyId = other.agencyId;
		balance = other.balance;
		game = other.game;
		procTime = other.procTime;
		currency_unit_multi = other.currency_unit_multi;
	}

	stCacheLoginInfo& operator = (const stCacheLoginInfo& other)
	{
		if (this == &other)
			return *this;

		agentSrvId = other.agentSrvId;
		uid = other.uid;
		tempUin = other.tempUin;
		agency = other.agency;
		agencyId = other.agencyId;
		username = other.username;
		token = other.token;
		balance = other.balance;
		game = other.game;
		hallUrl = other.hallUrl;
		platform = other.platform;
		ext = other.ext;
		currency = other.currency;
		procTime = other.procTime;
		trans = other.trans;
		currency_unit_multi = other.currency_unit_multi;
		currency_label = other.currency_label;

		return *this;
	}

	stCacheLoginInfo& operator = (stCacheLoginInfo&& other)
	{
		if (this == &other)
			return *this;

		agentSrvId = other.agentSrvId;
		uid = other.uid;
		tempUin = other.tempUin;
		agency = std::move(other.agency);
		agencyId = other.agencyId;
		username = std::move(other.username);
		token = std::move(other.token);
		balance = other.balance;
		game = other.game;
		hallUrl = std::move(other.hallUrl);
		platform = std::move(other.platform);
		ext = std::move(other.ext);
		currency = std::move(other.currency);
		procTime = other.procTime;
		trans = std::move(other.trans);
		currency_unit_multi = other.currency_unit_multi;
		currency_label = std::move(other.currency_label);

		return *this;
	}

};


#endif